# -*- coding: utf-8 -*-
"""
@Time ： 2023/7/4 21:51
@Auth ： 叶东宇
@File ：removeAllAdjacentDuplicatesInString.py
"""

def remove(s):
    stack = []
    for i in s:
        if len(stack) == 0:
            stack.append(i)
        else:
            if stack[-1] == i:
                stack.pop()
            else:
                stack.append(i)
    return ''.join(stack)

def remove_leetcode(s):
    stack = []
    for char in s:
        if stack and stack[-1] == char:
            stack.pop()
        else:
            stack.append(char)
    return "".join(stack)

if __name__ == "__main__":
    print(remove("aagghh"))